package com.ruoyi.web.controller.clothing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clothing.domain.SysCustomizationOrder;
import com.ruoyi.clothing.service.ISysCustomizationOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 定制订单管理Controller
 *
 * @author weh
 * @date 2024-01-21
 */
@RestController
@RequestMapping("/clothing/customized_order")
public class SysCustomizationOrderController extends BaseController
{
    @Autowired
    private ISysCustomizationOrderService sysCustomizationOrderService;

    /**
     * 查询定制订单管理列表
     */

    @GetMapping("/list")
    public List<SysCustomizationOrder> list(SysCustomizationOrder sysCustomizationOrder)
    {
        List<SysCustomizationOrder> list = sysCustomizationOrderService.selectSysCustomizationOrderList(sysCustomizationOrder);
        return list;
    }

    /**
     * 导出定制订单管理列表
     */

    @Log(title = "定制订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCustomizationOrder sysCustomizationOrder)
    {
        List<SysCustomizationOrder> list = sysCustomizationOrderService.selectSysCustomizationOrderList(sysCustomizationOrder);
        ExcelUtil<SysCustomizationOrder> util = new ExcelUtil<SysCustomizationOrder>(SysCustomizationOrder.class);
        util.exportExcel(response, list, "定制订单管理数据");
    }

    /**
     * 获取定制订单管理详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sysCustomizationOrderService.selectSysCustomizationOrderById(id));
    }

    /**
     * 新增定制订单管理
     */

    @Log(title = "定制订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCustomizationOrder sysCustomizationOrder)
    {
        return toAjax(sysCustomizationOrderService.insertSysCustomizationOrder(sysCustomizationOrder));
    }

    /**
     * 修改定制订单管理
     */

    @Log(title = "定制订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCustomizationOrder sysCustomizationOrder)
    {
        return toAjax(sysCustomizationOrderService.updateSysCustomizationOrder(sysCustomizationOrder));
    }

    /**
     * 删除定制订单管理
     */
    @Log(title = "定制订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysCustomizationOrderService.deleteSysCustomizationOrderByIds(ids));
    }

    /**
     * 私人定制下单功能
     * @param data
     * @return
     */
    @PostMapping("/customizedOrder")
    public AjaxResult customizedOrder(@RequestBody SysCustomizationOrder data){
        sysCustomizationOrderService.customizedOrder(data);
        return AjaxResult.success("下单成功");
    }

    /**
     * 根据用户类型获取用户信息
     * @param owner
     * @return
     */
    @GetMapping("/listByOwner/{owner}")
    public List<SysCustomizationOrder> listOrder(@PathVariable("owner") Integer owner){
        return sysCustomizationOrderService.listByOwner(owner);
    }

}
